package com.ruoyi.web.controller.xhs;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.controller.xhs.dto.XhsReqDTO;
import com.ruoyi.web.service.ApiService;
import com.ruoyi.web.service.RemoteService;
import com.ruoyi.xhs.entity.XhsSearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * XhsController
 *
 * @author Wayne Wei
 * @version 1.0
 * @date 2025/6/19
 * @description 小红书控制类
 */
@RestController
@RequestMapping("/xhs")
public class XhsController {

    @Autowired
    private ApiService apiService;

    @Autowired
    private RemoteService remoteService;

    /**
     * 通用上传请求（单个）
     */
    @PostMapping("/keywork")
    public AjaxResult uploadFile(@RequestBody XhsReqDTO request) {
        try {
            XhsSearchResult xhsSearchResult = apiService.searchSomeNote(
                    request.getQuery(),
                    request.getQueryNum(),
                    request.getCookies(),
                    request.getSortTypeChoice(),
                    request.getNoteType(),
                    request.getNoteTime(),
                    request.getNoteRange(),
                    request.getPosDistance(), null, null
            );
            AjaxResult ajax = AjaxResult.success(xhsSearchResult);
            return ajax;
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }



    @PostMapping("/fetchByType")
    public AjaxResult fetchByType(@RequestBody XhsReqDTO request) {
        try {
            XhsSearchResult xhsSearchResult = remoteService.fetchByType(request);
            AjaxResult ajax = AjaxResult.success(xhsSearchResult);
            return ajax;
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

}